export type Type =
  | "Array"
  | "Object"
  | "String"
  | "Number"
  | "Boolean"
  | "Null"
  | "Undefined"
  | "Function"
  | "Date"
  | "RegExp"
  | "Map"
  | "Set"
  | "Promise";

/**
 * 使用 Object.prototype 获取精确的类型
 * @param value 目标
 */
const getTypeByPrototype = (value: unknown) => {
  return Object.prototype.toString.call(value).slice(8, -1);
};

/**
 * 目标是否是指定类型
 * @param value 目标
 * @param type 类型
 */
export const isType = (value: unknown, type: Type) => {
  return getTypeByPrototype(value) === type;
};
